<?php
/**
 * BHelper class.
 * BHelper is the helper static class for business portal.
 * 
 * It used for HTML printing functions.
 * 
 * Yamii for Business
 * LBB Solutions Oy 版权所有 @ 2013.
 */
class BHelper {
	/**
	 *  Print the header for sign page
	 */
	public static function HtmlHeaderLogin() {
?>
<div class="header-login" style="margin-top:32px;">
    <div class="container">
        <div class="span-4 prepend-6" style="width:140px;">
			<img style="width:120px;" src="<?php echo Yii::app()->request->baseUrl; ?>/img/logo.icon.big.png" />
		</div>
        <div class="span-10 last">
			<h1 class="title1"><?php echo BUtils::T('yb_welcome'); ?></h1>
			<h3 class="title2" style="font-style:italic; font-size:24px; line-height:24px;">
				<?php echo BUtils::T('yb_brief'); ?>
			</h3>
		</div>
		<div class="clearfix"></div>
    </div>
</div>
<?php
	}
	
	/**
	 * print the footer
	 */
	public static function HtmlFooter() {
?>
<div id="footer">
	<div class="container">
		<div class="prepend-top append-bottom">
		<div class="about">
			<a href="http://yamii.fi">Yamii.fi</a> &copy; <?php echo date('Y') ?> ·
			<a href="<?php echo Yii::app()->createUrl('/help/about'); ?>"><?php echo BUtils::T('about_us_lbl'); ?></a>
			<!-- · <a href="<?php echo Yii::app()->createUrl('/help/privacy'); ?>"><?php echo BUtils::T('privacy_lbl'); ?></a>
			 · <a href="<?php echo Yii::app()->createUrl('/help/terms'); ?>"><?php echo BUtils::T('terms_lbl'); ?></a> -->
		</div>
		<div class="lang">
			<a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'en_GB')); ?>">English</a>
			 · <a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'fi_FI')); ?>">Suomi</a>
			 · <a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'zh_CN')); ?>">中文</a>
		</div>
		<div class="clear"></div>
<?php if (YII_DEBUG) { ?>
<b onclick="ajax_debug('<?php echo Yii::app()->createUrl('/ajax/debug', array('do' => 'show')); ?>')"></b>
<div id="debug-enable">
    <button class="btn little" onclick="ajax_debug('<?php echo Yii::app()->createUrl('ajax/debug', array('do' => 'show')); ?>');">Debug Session</button>
    <button class="btn little" onclick="ajax_debug('<?php echo Yii::app()->createUrl('ajax/debug', array('do' => 'clear')); ?>');">Clear Session</button>
</div>
<script type="text/javascript">
function ajax_debug(url) {
    $.get(url, function(data) {
        $('#message_tips').html(data).slideDown();
        $('#message_tips').click(function(){ $(this).slideUp(); });
    });
}
</script>
<?php } ?>
	</div>
	</div>
</div>
<?php
		//end the html print
	}
	
	
	/**
	 * print the ending scripts
	 */
	public static function HtmlScripts() {
		$fb_language_code = BUtils::GetFacebookLanguage(Yii::app()->language);
		$push_url = Yii::app()->createUrl('/accounts/push');
?>
<div id="fb-root"></div>
<script src="<?php echo Yii::app()->baseUrl . '/js/jq.plugins.js?v=' . Yii::app()->params['version']; ?>"></script>
<script src="<?php echo Yii::app()->baseUrl . '/js/jq.yamii.js?v=' . Yii::app()->params['version']; ?>"></script>
<script type="text/javascript">
function _push(d){$.post('<?php echo $push_url; ?>', d)}
(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/<?php echo $fb_language_code; ?>/all.js#xfbml=1&appId=<?php echo Yii::app()->params['facebook']['appId']; ?>";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php
if (!YII_DEBUG) {
	$logedIn = Yii::app()->user->isGuest ? 'false' : 'true';
?>
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33072428-1']);
  _gaq.push(['_trackPageview']);
  _gaq.push(['_trackPageLoadTime']);
  _gaq.push(['_setCustomVar', 1, 'Logged in', '<?php echo $logedIn; ?>', 2]);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
<?php } ?>
<?php
		//end the html print
	}
	
	public static function HtmlCompletionTips() {
		//1. fetch percent of profile
		$sql_profile = 'SELECT m.name, m.address, m.postcode, m.phone, m.city, m.url_logo, m.url_site, m.brief,
			t.cuisine_style, t.cuisine_type, t.meal_served, t.payment_options, t.service_languages, t.alcohol_license, t.dining_ambience, t.car_parking, t.additional_details
			FROM tbl_merchant_account m
			LEFT JOIN tbl_merchant_tags t ON m.id=t.id_merchant
			WHERE m.id=:id';
		$connection = Yii::app()->db;
		$command = $connection->createCommand($sql_profile);
		$aProfile = $command->queryRow(true, array('id'=>Yii::app()->user->id));
		
		//2. fetch open hours
		$sql_open_hours = 'SELECT COUNT(id_merchant) AS hours FROM tbl_merchant_open_hours WHERE id_merchant=:id_merchant';
		$command = $connection->createCommand($sql_open_hours);
		$aOpenHours = $command->queryRow(true, array('id_merchant'=>Yii::app()->user->id));
		
		//3. fetch the gallery
		$sql_galleries = 'SELECT COUNT(id_merchant) AS galleries FROM tbl_merchant_gallery WHERE id_merchant=:id_merchant';
		$command = $connection->createCommand($sql_galleries);
		$aGalleries = $command->queryRow(true, array('id_merchant'=>Yii::app()->user->id));
		$connection->active = false;
		
		//5. fetch the specials
		$sql_specials = 'SELECT COUNT(id_merchant) AS specials FROM tbl_merchant_special WHERE id_merchant=:id_merchant AND end_date<NOW() AND trash=0';
		$command = $connection->createCommand($sql_specials);
		$aSpecials = $command->queryRow(true, array('id_merchant'=>Yii::app()->user->id));
		$connection->active = false;
		
		$progress = 0;
		$items = '';
		if (!empty($aProfile['name'])) $progress += 10;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/profile#company_name_lbl').'">'.BUtils::T('add_business_name_lbl').'</a> (+10%)</li>';
		if (!empty($aProfile['address'])) $progress += 10;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/profile#company_address_lbl').'">'.BUtils::T('add_location_lbl').'</a> (+10%)</li>';
		if (!empty($aProfile['phone'])) $progress += 10;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/profile#company_phone_lbl').'">'.BUtils::T('add_phone_lbl').'</a> (+10%)</li>';
		if (!empty($aProfile['brief'])) $progress += 10;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/profile#company_brief_lbl').'">'.BUtils::T('add_business_brief_lbl').'</a> (+10%)</li>';
		if ($aOpenHours['hours'] > 1) $progress += 15;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/profile#open_hours_lbl').'">'.BUtils::T('add_open_hours_lbl').'</a> (+15%)</li>';
		if (!empty($aProfile['cuisine_type'])) $progress += 10;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/feature').'">'.BUtils::T('add_detail_features_lbl').'</a> (+10%)</li>';
		if ($aGalleries['galleries'] > 0) $progress += 15;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/merchant/gallery').'">'.BUtils::T('add_photo_gallery_lbl').'</a> (+15%)</li>';
		if ($aSpecials['specials'] > 0) $progress += 20;
		else $items .= '<li><a href="'.Yii::app()->createUrl('/special/form').'">'.BUtils::T('create_special_lbl').'</a> (+20%)</li>';
		
		if ($progress < 100) {
?>
<div class="box_white append-bottom">
	<div class="biz-form margin">
		<h3><?php echo BUtils::T('completeness_lbl', array('{percent}' => $progress.'%')); ?></h3>
		<div>
			<div class="ui-progressbar ui-widget ui-widget-content ui-corner-all">
				<div style="background:#ad3; width:<?php echo $progress . '%'; ?>;" class="ui-progressbar-value ui-widget-header ui-corner-left"></div>
			</div>
		</div>
		<div class="tips">
			<ul class="add-tips">
				<?php echo $items; ?>
			</ul>
		</div>
	</div>
</div>
<?php
		}
	}
	
	public static function HtmlLanguageButtons() {
?>
<!-- language selector starts -->
<div class="btn-group" >
	<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
		<i class="icon-globe blue"></i><span class="hidden-phone"> <?php echo BUtils::T('_LNG_NAME'); ?></span>
		<span class="caret"></span>
	</a>
	<ul class="dropdown-menu dropdown-yellow">
		<li><a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'en_GB')); ?>"><i class="icon-blank"></i> English</a></li>
		<li><a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'fi_FI')); ?>"><i class="icon-blank"></i> Suomi</a></li>
		<li><a href="<?php echo Yii::app()->createUrl('/site/language', array('lang' => 'zh_CN')); ?>"><i class="icon-blank"></i> 简体中文</a></li>
	</ul>
</div>
<?php
	}
	
	public static function HtmlErrorWell() {
?>
<div class="well well-large gray">
	<h3 class=""><?php echo BUtils::T('error_system_lbl'); ?></h3>
	<p><?php echo BUtils::T('error_system_eg'); ?></p>
</div>
<?php
	}
}